package com.springboot.controller;

import com.springboot.model.AssistantListFormKey;
import com.springboot.model.UserLoginForm;
import com.springboot.service.DoctorViewAssistantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

/**
 * 本控制台用于医生查看助理列表
 */
@Controller
public class DoctorViewAssistantController {
    @Autowired
    DoctorViewAssistantService doctorViewAssistantService;
    /**
     * 医生查看助理列表
     */
    @CrossOrigin
    @RequestMapping(value = "/getAssistantListServlet")
    public @ResponseBody
    String doctorViewAssistant(@RequestParam("doctorID") String doctorTel) {
        System.out.println("医生查看助理列表");
        try {
            UserLoginForm doctor=doctorViewAssistantService.findUserByTel(doctorTel);
            int doctorId=doctor.getUserId();
            ArrayList<AssistantListFormKey> assistantListFormKeys=doctorViewAssistantService.findAssistantByDoctor(doctorId);
            int []assistantId=new int[assistantListFormKeys.size()];
            ArrayList<UserLoginForm> userLoginForms=new ArrayList<>();
            if(assistantListFormKeys.size()>0)
            {
                for(int i=0;i<assistantListFormKeys.size();i++)
                {
                    AssistantListFormKey assistantListFormKey=assistantListFormKeys.get(i);
                    assistantId[i]=assistantListFormKey.getAssistantId();
                    UserLoginForm userLoginForm=doctorViewAssistantService.findUserById(assistantId[i]);
                    UserLoginForm assistant=new UserLoginForm();
                    assistant.setLogoLink(userLoginForm.getLogoLink());
                    assistant.setUserName(userLoginForm.getUserName());
                    assistant.setUserTel(userLoginForm.getUserTel());
                    userLoginForms.add(assistant);
                }
                System.out.println(userLoginForms.toString());
                return userLoginForms.toString();
            }
            else
            {
                return "空";
            }
        } catch (Exception e) {
            return "False";
        }
    }
}